#!/bin/bash
path_dir=${PWD}

source ${path_dir}/../../shrc


for files_dir in "${path_dir}"/*;do
        if [ -d "${files_dir}" ];then
                test="$(basename "${files_dir}")"
                echo "${test}"
                pushd ${files_dir}/src
                source ../execInfo
                filename=$(find -name "${test}.*")
                exe_file="$(basename "${filename}")"
			if [ -f "${files_dir}/src/${test}" ];then
				rm -rf ${files_dir}/src/${test}
			fi
                        if [ ! -f "${files_dir}/src/${test}" ];then
				if [ "${exe_file#*.}" = "c" ];then
					clang ${files_dir}/src/${exe_file} -o ${files_dir}/src/${test} -lm
				fi
				if [ "${exe_file#*.}" = "cpp" ];then
					clang++ ${files_dir}/src/${exe_file} -o ${files_dir}/src/${test}
				fi
                        fi

                        if [ -f "${files_dir}/src/${test}" ];then
                                { time NUM_WORKERS=4 ${files_dir}/src/${test} ${TESTARG}; } 2>${files_dir}/src/time.txt
                        fi
                        if [ -f "${files_dir}/src/time.txt" ];then
                                while read line
                                do
                                        if [ -n "${line}" ];then
                                                xx=${test}','${line}
                                                echo ${xx} >> "${path_dir}/test_time_clang_benchmark.csv"
                                        fi
                                done <"${files_dir}/src/time.txt"
                        fi

                popd
        fi
done
sed -i 's/ 0m/,0m/g' "${path_dir}/test_time_clang_benchmark.csv"

